//
//  LBWNavigationController.swift
//  weibo
//
//  Created by Limonwei on 15/12/5.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

class LBWNavigationController: UINavigationController,UIGestureRecognizerDelegate {
    
    override func viewDidLoad() {
        //
        super.viewDidLoad()
        
        //bug:如果在根控制器边缘向右滑,,再次push控制器的话会失效
        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //
        
        if childViewControllers.count != 0 {
            
            var title: String = "返回"
            
            if childViewControllers.count == 1 {
                
                title = childViewControllers.first!.title ?? title
            }
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            
            //隐藏底部 tabbar
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func back(){
        
        popViewControllerAnimated(true)
        
    }
    
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        // 判断如果是根控制器就不要识别这个手势 ,就解决了这个bug
        
        return childViewControllers.count != 1
    }
    

}






























